cudarc: minimal and safe api over the cuda toolkit
Checkout cudarc on crates.io and docs.rs.
Safe abstractions over:
Pre-alpha state, expect breaking changes and not all cuda functions contain a safe wrapper. Contributions welcome for any that aren't included!
Design
Goals are:
- As safe as possible (there will still be a lot of unsafe due to ffi & async)
- As ergonomic as possible
- Allow mixing of high level
safe
apis, with low levelsys
apis
To that end there are three levels to each wrapper (by default the safe api is exported):
use ;
use ;
use ;
use ;
use ;
use ;
where:
sys
is the raw ffi apis generated with bindgenresult
is a very small wrapper around sys to returnResult
from each functionsafe
is a wrapper around result/sys to provide safe abstractions
Heavily recommend sticking with safe APIs
API Preview
It's easy to create a new device and transfer data to the gpu:
let dev = new?;
// allocate buffers
let inp = dev.htod_copy?;
let mut out = dev.?;
You can also use the nvrtc api to compile kernels at runtime:
let ptx = compile_ptx?;
// and dynamically load it into the device
dev.load_ptx?;
cudarc
provides a very simple interface to launch kernels, tuples
are the arguments!
let sin_kernel = dev.get_func.unwrap;
let cfg = for_num_elems;
unsafe ?;
And of course it's easy to copy things back to host after you're done:
let out_host: = dev.dtoh_sync_copy?;
assert_eq!;
License
Dual-licensed to be compatible with the Rust project.
Licensed under the Apache License, Version 2.0 http://www.apache.org/licenses/LICENSE-2.0 or the MIT license http://opensource.org/licenses/MIT, at your option. This file may not be copied, modified, or distributed except according to those terms.